package GUI;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

import main.ScreenController;

import GUI.AddBooking.CustomerViewAvailableRoomsPanel;
import GUI.TabPanels.CustomerBookingPanel;

@SuppressWarnings("serial")
public class CustomerScreen extends JPanel{
	private static CustomerScreen instance;

	private int customerID;

	private CustomerBookingPanel cust_booking_panel;
	private CustomerViewAvailableRoomsPanel cust_avail_rooms;
	
	private JButton logout_button;
	
	private ScreenController sc;
	/*
	private BookingPanel booking_panel;
	private CheckInPanel check_in_panel;
	private CheckOutPanel check_out_panel;
	private ViewGuestsPanel view_guests_panel;
	private AddFeesPanel add_fees_panel;
	private AdminPanel admin_panel;*/

	private CustomerScreen(){
		this.setLayout(new BorderLayout());

		sc = ScreenController.getInstance();
		
		logout_button = new JButton("Logout");
		
		logout_button.addActionListener(new LogoutButton());
		this.add(logout_button, BorderLayout.EAST);
		setSize(900,600);

		//tabs.addChangeListener(new TabChanged());

		setVisible(true);
	}

	public void initializePanels(){
		cust_booking_panel = new CustomerBookingPanel();
		cust_avail_rooms = new CustomerViewAvailableRoomsPanel();
		this.add(cust_booking_panel, BorderLayout.SOUTH);
	}

	public static CustomerScreen getInstance(){
		if(instance == null)
			instance = new CustomerScreen();
		return instance;
	}

	public void UpdateAvailableRooms() {
		cust_avail_rooms.Update();
	}

	public void ViewRooms(){
		this.remove(cust_booking_panel);
		this.add(cust_avail_rooms, BorderLayout.SOUTH);
		cust_avail_rooms.Update();
		this.paint(getGraphics());
	}

	// input[0] -> hotelID
	// input[1] -> start_date
	// input[2] -> end_date
	public String[] getAvailableRoomsInfo() {
		String[] booking_dates = getBookingDates();
		String[] results = {cust_booking_panel.getHotelID(), booking_dates[0], booking_dates[1]};
		return results;
	}

	public String[] getBookingDates(){
		String[] booking_info = cust_booking_panel.getBookingDates();
		return booking_info;
	}

	public void AddBooking() {
		this.remove(cust_avail_rooms);
		this.add(cust_booking_panel, BorderLayout.SOUTH);	
		this.paint(getGraphics());		
	}

	public int getID() {
		return customerID;
	}

	public void setID(int ID) {
		customerID = ID;		
	}

	private class LogoutButton implements ActionListener{
		@Override
		public void actionPerformed(ActionEvent arg0) {
			sc.ViewLoginScreen();
		}
	}
	/*
	private class TabChanged implements ChangeListener{

		@Override
		public void stateChanged(ChangeEvent e) {
			/*check_in_panel.UpdateTable();
			check_out_panel.UpdateTable();
			view_guests_panel.UpdateTable();*/

	//tabs.repaint();

	//			if(tabs.getSelectedComponent() == check_in_panel){
	//				check_in_panel.Update();
	//			}else if(tabs.getSelectedComponent() == check_out_panel){
	//				check_out_panel.Update();
	//			}else if(tabs.getSelectedComponent() == view_guests_panel){
	//				view_guests_panel.Update();
	//			}
	//tabs.repaint();
	//}

	//}*/
}
